package com.wowangz.cms.topic.attachment.service;

import java.util.List;
import java.util.Map;

import com.wowangz.cms.syscore.exception.ServiceException;
import com.wowangz.cms.syscore.service.BaseService;
import com.wowangz.cms.topic.attachment.entity.Attachment;

public class AttachmentService extends BaseService {
	
	/**
	 * @描述：添加附件
	 * @author HUANGYUAN
	 * @TIME:2015年9月22日 下午5:26:42
	 * @param poster
	 * @return
	 * @throws ServiceException
	 */
	public String attachmentSave(Attachment attachment) throws ServiceException {
		try {
			this.getSqlSession().insert("AttachmentService.saveAttachment", attachment);
			String id = "" + attachment.getId();
			return id;
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	
	/**
	 * @描述：删除附件
	 * @author HUANGYUAN
	 * @TIME:2015年9月22日 下午5:27:54
	 * @param attachment
	 * @throws ServiceException
	 */
	public void deleteAttachment(Attachment attachment) throws ServiceException{
		try {
			this.getSqlSession().update("AttachmentService.updateAttachment", attachment);
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	
	/**
	 * @描述：修改附件的信息
	 * @author HUANGYUAN
	 * @TIME:2015年9月22日 下午2:16:38
	 * @param poster
	 * @throws ServiceException
	 */
	public void updatePoster(Attachment attachment) throws ServiceException{
		try {
			this.getSqlSession().update("AttachmentService.updateAttachment", attachment);
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	
	/**
	 * @描述：获得海报的总记录数目
	 * @author HUANGYUAN
	 * @TIME:2015年9月22日 下午2:20:03
	 * @param map
	 * @return
	 */
	public Long findAttachmentCountByMap(Map<String, Object> map){
		try {
			Object object = this.getSqlSession().selectOne("AttachmentService.findAttachmentCountByMap", map);
			return (Long) object;
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	
	/**
	 * @描述：查询最大排序编号
	 * @author HUANGYUAN
	 * @TIME:2015年9月22日 下午3:31:26
	 * @return
	 */
	public Long findMaxSortnumber(){
		try {
			Object object = this.getSqlSession().selectOne("AttachmentService.findMaxSortnumber");
			return (Long) object;
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}

	/**
	 * @描述：查询一条数据
	 * @author HUANGYUAN
	 * @TIME:2015年9月22日 下午5:29:46
	 * @param map
	 * @return
	 */
	public Attachment findOneAttachmentByMap(Map<String, Object> map){
		try {
			Object object = this.getSqlSession().selectOne("AttachmentService.findOneAttachmentByMap", map);
			return (Attachment) object;
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	
	/**
	 * 获得海报的结果集合
	 * @描述：
	 * @author HUANGYUAN
	 * @TIME:2015年9月22日 下午2:20:26
	 * @param map
	 * @return
	 */
	public List<Attachment> findAttachmentPageByMap(Map<String, Object> map){
		try {
			List<Attachment> objects = this.getSqlSession().selectList("AttachmentService.findAttachmentPageByMap", map);
			return objects;
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
	public List<Attachment> findAttachmentAll(Map<String, Object> map){
		try {
			List<Attachment> objects = this.getSqlSession().selectList("AttachmentService.findAttachmentAll", map);
			return objects;
		} catch (ServiceException e) {
			throw new ServiceException(e.getMessage());
		}
	}
}
